package com.zr.controller.order;

import com.zr.service.order.OrderGoodsService;
import com.zr.utils.AjaxResult;
import com.zr.vo.order.OrderGoods;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.Map;

/**
 * 订单货物处理
 * @author huangguilong
 */
@RestController
@RequestMapping("/order/goods")
public class OrderGoodsController {

    @Resource
    private OrderGoodsService orderGoodsService;

    /**
     * 查询货物列表
     * @param goodsOrderId
     * @return Map<String, Object>
     * @author huangguilong
     */
    @RequestMapping("/list/{orderId}")
    public AjaxResult list(@PathVariable("orderId") String goodsOrderId) {
        Map<String, Object> map = orderGoodsService.getGoodsByOrderId(goodsOrderId);
        return AjaxResult.success(200, "查询成功", map);
    }

    /**
     * 新增货物
     * @param orderId
     * @param orderGoods
     * @return
     * @author huangguilong
     */
    @RequestMapping("/add/{orderId}")
    public AjaxResult add(@PathVariable("orderId") String orderId, @RequestBody OrderGoods orderGoods) {
        orderGoods.setGoodsOrderId(orderId);
        orderGoodsService.add(orderGoods);
        return AjaxResult.success(200, "新增成功", null);
    }

    /**
     * 编辑货物
     * @param orderGoods
     * @return
     * @author huangguilong
     */
    @RequestMapping("/edit")
    public AjaxResult edit(@RequestBody OrderGoods orderGoods) {
        orderGoodsService.edit(orderGoods);
        return AjaxResult.success(200, "修改成功", null);
    }

    /**
     * 删除货物
     * @param orderGoods
     * @return
     * @author huangguilong
     */
    @RequestMapping("/remove")
    public AjaxResult remove(@RequestBody OrderGoods orderGoods) {
        orderGoodsService.remove(orderGoods);
        return AjaxResult.success(200, "删除成功", null);
    }

    /**
     * 删除所有未生成委托订单的货物信息
     * @return
     * @author huangguilong
     */
    @RequestMapping("/clearGoodsList")
    public AjaxResult clearGoodsList() {
        orderGoodsService.deleteAllByOrderId();
        return AjaxResult.success(200, "删除成功", null);
    }
}
